package com.ghsc.ghxc.jsb.ui.home.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.EarnIntegralResult
import com.ghsc.ghxc.jsb.ui.home.bean.SignInBean
import com.ghsc.ghxc.jsb.ui.home.bean.TasksStateResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.home.activity
 * 类名：EarnIntegral
 * 创建时间：2024/5/6 20:53
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class EarnIntegralViewModel : BaseViewModel() {


    /**
     * 任务初始化
     */
    var onRenwuIndex = MutableLiveData<BaseResponse<EarnIntegralResult>>()
    fun onRenwuIndexMethod(p:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onRenwuIndex(p) }
            executeResponse(
                response,
                { onRenwuIndex.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 任务领取
     */
    var onReadyRenwu = MutableLiveData<BaseResponse<Any>>()
    fun onReadyRenwuMethod(p:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onReadyRenwu(p) }
            executeResponse(
                response,
                { onReadyRenwu.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 任务每个完成
     */
    var onActRenwu = MutableLiveData<BaseResponse<SignInBean>>()
    fun onActRenwuMethod(p:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onActRenwu(p) }
            executeResponse(
                response,
                { onActRenwu.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /**
     * 获取日常任务
     */
    var onZbTaskListData = MutableLiveData<BaseListResponse<TasksStateResult>>()
    fun onZbTaskListMethod(json:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbTaskListData(json) }
            executeListResponse(
                response,
                { onZbTaskListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


}